package 购票thread框的形式;

import javax.swing.*;
import java.util.List;

public class SailTick extends Thread{
    private List<Ticks> lists;
    private JTextArea ta;

    public SailTick(List<Ticks> lists, JTextArea ta) {
        this.lists = lists;
        this.ta = ta;
    }

    @Override
    public void run() {
        int c=0;
        while (true){
            Ticks t;
            //上锁---避免线程的不确定性（如：卖票避免重复卖）
            synchronized (lists) {
                if(lists.size()<=0)break;
                t = lists.remove(0);
                c++;
            }
            ta.append(Thread.currentThread().getName()+"卖了"+t+"\n");
        }
        ta.append(Thread.currentThread().getName()+"卖了"+c+"张！"+"\n");
    }
}
